const swiperContent = document.getElementById('swiperContent');//轮播图ul
const pre = document.getElementById('pre');//上一个按钮
const next = document.getElementById('next');//下一个一个按钮

const width = screen.width;//屏幕宽度
let timer;
let distance = 0;

//上一张
pre.onclick = () => {
    if (distance == -66.66) {
        distance = 0;
        swiperContent.style.left = distance + "%";
    } else {
        distance += -33.33;
        swiperContent.style.left = distance + "%";
    }
}
//下一张
next.onclick = () => {
    if (distance == 0) {
        distance = -66.66;
        swiperContent.style.left = distance + "%";
    } else {
        distance += 33.33;
        swiperContent.style.left = distance + "%";
    }
}

//定时器
if (screen.width >= 992) {
    timer = setInterval(() => {
        if (distance == -66.66) {
            distance = 0;
            swiperContent.style.left = distance + "%";
        } else {
            distance += -33.33;
            swiperContent.style.left = distance + "%";
        }
    }, 3000)
}


//在屏幕分辨率小于992时取消定时器
window.onresize = function (e) {
    if (screen.width >= 992) {
        clearInterval(timer);
        timer = setInterval(() => {
            if (distance == -66.66) {
                distance = 0;
                swiperContent.style.left = distance + "%";
            } else {
                distance += -33.33;
                swiperContent.style.left = distance + "%";
            }
        }, 3000)
    } else {
        clearInterval(timer);
    }
}